var text = [{
  title: '详情', endTime: '申请截止时间', reward: '报酬', deadline: '任务截止期限',
  time: '申请时间', apply: '申请', cancel: '取消', report: '报告', finish: '结题',
  submit: '已提交', back: '返回', del: '终止', sending: '正在处理', phone: '联系方式：',
  record: '结题申请驳回记录',
}, {
  title: '详情', endTime: '申请截止时间', reward: '报酬', deadline: '任务截止期限',
  time: '申请时间', apply: '申请', cancel: '取消', report: '报告', finish: '结题',
  submit: '已提交', back: '返回', del: '终止', sending: '正在处理', phone: '联系方式：',
  record: '结题申请驳回记录',
}],
modal = [{
  toast: '你已经提交过结题申请啦，耐心等待发布人同意吧~',
  finish: '向发布者申请结题', finish0: '若本次申请被驳回，您仍能重新提交申请。', finish2: '前往结题'
}, {
  toast: '你已经提交过结题申请啦，耐心等待发布人同意吧~',
  finish: '向发布者申请结题', finish0: '若本次申请被驳回，您仍能重新提交申请。',finish2: '前往结题'
}];
var animating, sending;
Page({

  data: {
    showMask: true,
    sign: false,
    submit: null,
  },

  onLoad: function (options) {
    sending = animating = 0;
    let item = JSON.parse(decodeURIComponent(options.content));
    if (item.gmtdead != '0')
      item.deadline = wx.formatTime(new Date(parseInt(item.gmtdead) * 1e3), '/');
    else 
      item.deadline = 0;
    this.setData({
      item: item,
      text: text[wx.lang],
      theme: wx.theme,
    });
    wx.post('PracticeItem.getSubmit', { idPracticeItem: item.itemInfo.idpracticeitem}, submit => {
      if (submit.data.content) {
        this.setData({
          submit: submit.data
        })
      }
    })
  },

  onShow() {
    wx.onShow(this, text[wx.lang].title, wx.theme);
  },

  report() {
    if (animating++) return;
    let sign_up = this.data.item.sign_up
    wx.slide_v(this, ['group1'], wx.system.height, 0, .5, () => {
      this.setData({ hideGroup: true });
      wx._slide_v(this, ['group2'], wx.system.height, 0, () => {
        wx.slide_v(this, ['group2'], 0, 1, 0, () => {
          animating = 0;
        })
      })
    })
  },

  havingSubmitted() {
    wx.toast(modal[wx.lang].toast)
  },
  finish() {
    wx.modal(modal[wx.lang].finish, modal[wx.lang].finish0, null, modal[wx.lang].finish2,
    null, '#008B00', () => {
      wx.nav('../submit/submit?id=' + this.data.item.itemInfo.idpracticeitem);
    })
  },
  
  cancel() {
    wx.toast('功能暂未开放')
  },
  
  call(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.id,
    })
  },

  onShareAppMessage: function () {
    return wx.onShareAppMessage();
  }
})